﻿@model WaiGaoQiaoWeb.Models.FundsOperatingVM
@{
    ViewBag.Title = "ReduceMoney";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm")
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#btnCancel").click(function (e) {
                CloseModelWindow(null, false);
            });

            $("#btnSave").click(function (event) {
                if (!$("#fmEdit").valid()) {
                    return false;
                }
                var allvalue = "";
                if ($("#rightbox")[0].all.length == 0) {
                    showLoadingMsg("请选择要减款的员工!", { left: 500, top: 6 }, true, 3000);
                    return false;
                }
                for (var v1 = 0; v1 < $("#rightbox")[0].all.length; v1++) {
                    allvalue += $("#rightbox")[0][v1].value;
                    allvalue += ",";
                }
                document.getElementById("EmpAll").value = allvalue;
                $('#fmEdit').ajaxSubmit(function (callback) {
                    if (callback) {
                        //CloseModelWindow(null, true);
                        showLoadingMsg("减款成功!", { left: 500, top: 6 }, true, 3000);
                        return false;
                    }
                    else {
                        showLoadingMsg("减款失败!", { left: 500, top: 6 }, true, 3000);
                        return false;
                    }
                });
            });
        });
        function select() {
            var vempno = $("#txtEmpNo").val();
            var vpname = $("#txtPName").val();
            var vdeptname = $("#ddldeptName").val();
            var vcardserial = $("#txtCardSerial").val();
            var query = vempno + ',' + vpname + ',' + vdeptname + ',' + vcardserial;
            //$('#CardReportLossList').flexOptions(option).flexReload();
            var rowcount = 0;
            $.ajax({
                type: "POST",
                url: '@Url.Action("GetLeftBox")',
                data: { Select: query },
                dataType: "json",
                async: true,
                success: function (data) {
                    $("#leftbox").empty();
                    var t = $("#leftbox")
                    for (var i in data) {
                        var x = data[i];
                        t.append("<option value='" + x.Value + "'>" + x.Text + "</option>");
                    }
                },
                error: function () { }
            });
        }

        function myRight()//将select框中选中的列，移到另一个select框中
        {
            var select_b1 = document.getElementById("leftbox");
            var select_b2 = document.getElementById("rightbox");

            var count = 0;
            for (i = 0; i < select_b1.length; i++) {
                count = 0;
                if (select_b1.options[i].selected) {
                    var temp = document.createElement("option");
                    temp.value = select_b1[i].value;
                    temp.text = select_b1[i].text;
                    if (select_b2.length == 0) {
                        select_b2.add(temp);
                    }
                    else {
                        for (j = 0; j < select_b2.length; j++) {
                            if (select_b2.options[j].value == temp.value) {
                                count++;
                            }
                        }
                        if (count == 0) {
                            select_b2.add(temp);
                        }

                    }
                }
            }
        }

        function myRightAll()//将select框中选中的列，全部移到另一个select框中
        {
            var select_b1 = document.getElementById("leftbox");
            var select_b2 = document.getElementById("rightbox");
            for (i = select_b2.length; i >= 0; i--) {
                select_b2.remove([i]);
            }
            if (select_b2.length == 0) {
                for (i = 0; i < select_b1.length; i++) {
                    var temp = document.createElement("option");
                    temp.value = select_b1[i].value;
                    temp.text = select_b1[i].text;
                    select_b2.add(temp);
                }
            }
        }

        function myleft()//将select框中选中的列删除
        {
            var select_b2 = document.getElementById("rightbox");
            var tmp = select_b2.length;
            for (i = 0; i < select_b2.length; i++) {
                if (select_b2.options[i].selected) {
                    select_b2.remove([i]);
                    i--;
                }

            }
        }
        function myleftAll()//全部删除将select框中的列
        {
            var select_b1 = document.getElementById("leftbox");
            var select_b2 = document.getElementById("rightbox");
            for (i = select_b2.length; i >= 0; i--) {
                select_b2.remove([i]);
            }
        }

    </script>
}
@using (Html.BeginForm("SaveReduceMoney", "FundsOperating", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.EmpAll)
    <div class="mainpanel">
        <table cellpadding="0" cellspacing="0" style="width: 100%; height: auto">
            <tr>
                <td style="width: 70%">
                    <table cellpadding="0" cellspacing="6" style="width: 100%; height: auto">
                        <tr>
                            <td colspan="3">
                                人员姓名：@Html.TextBox("txtPName", "", new { @style = "width:120px;" })&nbsp;&nbsp;
                                人员工号：@Html.TextBox("txtEmpNo", "", new { @style = "width:120px;" })
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <table cellpadding="0" cellspacing="0" style="width: 100%; height: auto">
                                    <tr>
                                        <td>
                                            所在部门：@Html.DropDownList("ddldeptName", ViewData["deptName"] as IEnumerable<SelectListItem>,
                                                        new { @style = "width:130px; height:20px; font-size:13px;" })
                                        </td>
                                        <td>
                                            卡号序列：@Html.TextBox("txtCardSerial", "", new { @style = "width:120px;" })
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <a id="butfind" class="button" href="javascript:void(0);" onclick="select();"><span>
                                    查询</span></a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @Html.ListBoxFor(model => model.leftbox,
                            ViewData["cardleft"] as IEnumerable<SelectListItem>,
                            new { @style = "width:150px; height:280px; font-size:13px;" })
                            </td>
                            <td>
                                <a id="btnRight" href="javascript:void(0);" class="button" onclick="myRight()"><span>
                                    ></span></a><br />
                                <br />
                                <a id="btnLeft" href="javascript:void(0);" class="button" onclick="myleft()"><span><</span></a><br />
                                <br />
                                <a id="btnRightAll" href="javascript:void(0);" class="button" onclick="myRightAll()">
                                    <span>>></span></a><br />
                                <br />
                                <a id="btnLeftAll" href="javascript:void(0);" class="button" onclick="myleftAll()"><span>
                                    <<</span></a>
                            </td>
                            <td>
                                @Html.ListBoxFor(model => model.rightbox,
                            ViewData["cardright"] as IEnumerable<SelectListItem>,
                            new { @style = "width:150px; height:280px; font-size:13px;" })
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width: 30%">
                    <table cellpadding="0" cellspacing="6" style="width: 100%; height: auto">
                        <tr>
                            <td>
                                @Html.LabelFor(model => model.DepositName)
                            </td>
                            <td>
                                @Html.DropDownListFor(model => model.DepositName,
                                    ViewData["DepositTypeIDReduce"] as IEnumerable<SelectListItem>,
                                    new { @style = "width:90px; height:22px; font-size:13px;" })
                                @Html.ValidationMessageFor(model => model.DepositName)
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @Html.LabelFor(model => model.Money)
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.Money, new { Class = "uc", @style = "width:80px" })<span
                                    style="color: Red;">*</span>
                                @Html.ValidationMessageFor(model => model.Money)
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="buttonpanel">
                                    <div style="float: right; margin-right: 10px;">
                                        <a id="btnSave" href="javascript:void(0);" class="button"><span>保存</span></a> <a
                                            id="btnCancel" href="javascript:void(0);" class="button"><span>关闭</span></a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
}